package com.hzhr.iot.cqgas.ds.controller;

import com.hzhr.iot.cqgas.ds.dao.device.example.DevCollectDeviceDao;
import com.hzhr.iot.cqgas.ds.dao.user.example.UsrDeptDao;
import com.hzhr.iot.cqgas.ds.entity.device.DevCollectDeviceEntity;
import com.hzhr.iot.cqgas.ds.entity.device.DevCollectDeviceExample;
import com.hzhr.iot.cqgas.ds.entity.user.UsrDeptEntity;
import com.hzhr.iot.cqgas.ds.entity.user.UsrDeptExample;
import com.hzhr.iot.cqgas.ds.service.CollectDeviceService;
import com.hzhr.iot.cqgas.ds.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class RegulatorDeviceController {
    @Autowired
    CollectDeviceService collectDeviceService;
    @Autowired
    DevCollectDeviceDao devCollectDeviceDao;

    @RequestMapping(value = "/syncRegulatorDevice")
    public void syncRegulatorDevice() {
        DevCollectDeviceEntity devCollectDeviceEntity = new DevCollectDeviceEntity();
        devCollectDeviceEntity.setState("3");
        DevCollectDeviceExample example = new DevCollectDeviceExample();
        List<String> categoryCodes = new ArrayList<>();
        categoryCodes.add("7");
        categoryCodes.add("8");
        example.createCriteria().andOutIdIsNotNull().andCategoryCodeIn(categoryCodes);
        devCollectDeviceDao.updateByExampleSelective(devCollectDeviceEntity, example);

        collectDeviceService.syncRegulatorDevice();

        example = new DevCollectDeviceExample();
        example.createCriteria().andStateEqualTo("3").andOutIdIsNotNull().andCategoryCodeIn(categoryCodes);
        devCollectDeviceDao.deleteByExample(example);
    }

    @RequestMapping(value = "/syncRegulatorDevice_one")
    public void syncRegulatorDevice_one(@RequestParam("code") String code) {
        collectDeviceService.syncRegulatorDevice_one(code);
    }
}
